﻿using Sustainalytics.ESG.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace Sustainalytics.CRT.Synchronization
{
    public static class FocusedRatingsAssementManager
    {

        public static Task<RPAssessment> GetAssesment(double companyScore, List<Sustainalytics.Entities.ESGRatings.EsgFocusThresholds> thresholds)
        {
            thresholds = thresholds.OrderByDescending(x => x.LowerBound).ToList();
            var thesholdIndex = thresholds.FindIndex(t => t.LowerBound <= companyScore && companyScore < t.UpperBound);

            if (thesholdIndex < 0) return Task.FromResult(new RPAssessment());

            var focusThresholds = thresholds[thesholdIndex];
            return Task.FromResult(new RPAssessment { Id = thesholdIndex + 1, Name = focusThresholds.Value });
        }
    }
}